package com.yingside.collection;

import java.util.*;

public class TestMap {
    public static void main(String[] args) {
        /*Map<Integer,String> map = new HashMap<>();
        map.put(1,"aaa");
        map.put(2,"bbb");
        map.put(3,"ccc");
        map.put(4,"ddd");
        map.put(5,"ddd");

        //通过键获取值
        String s = map.get(1);
        //得到map所有的键
        Set<Integer> keys = map.keySet();

        //循环键，通过键得到值
        for (Integer k:keys) {
            System.out.println(k + "===" + map.get(k));
        }

        //获取所有的值
        Collection<String> values = map.values();
        for (String ss:values) {
            System.out.println(ss);
        }*/


        Map<String, List<Teacher>> map = new HashMap<>();

        Teacher t1 = new Teacher(1,"张老师1");
        Teacher t2 = new Teacher(2,"张老师2");
        Teacher t3 = new Teacher(3,"张老师3");
        Teacher t4 = new Teacher(4,"张老师4");
        Teacher t5 = new Teacher(5,"张老师5");

//        通过集合查找对应名字的对象
        /*List<Teacher> ts = new ArrayList<>();
        ts.add(t1);
        ts.add(t2);
        ts.add(t3);
        ts.add(t4);
        ts.add(t5);

        Teacher t = null;
        for (int i = 0; i < ts.size(); i++) {
            if(ts.get(i).getTeacherName().equals("张老师1")){
                t = ts.get(i);
                break;
            }
        }*/

//        通过简直对查找对应名字的对象
        Map<String,Teacher> ts = new HashMap<>();
        ts.put("张老师1",t1);
        ts.put("张老师2",t2);
        ts.put("张老师3",t3);
        ts.put("张老师4",t4);
        ts.put("张老师5",t5);

        Teacher teacher = ts.get("张老师1");
        System.out.println("teacher = " + teacher);


        /*List<Teacher> teachers1 = new ArrayList<>();
        teachers1.add(t1);
        teachers1.add(t2);

        List<Teacher> teachers2 = new ArrayList<>();
        teachers2.add(t3);
        teachers2.add(t4);

        List<Teacher> teachers3 = new ArrayList<>();
        teachers3.add(t5);

        map.put("ts1",teachers1);
        map.put("ts2",teachers2);
        map.put("ts3",teachers3);

        List<Teacher> teachers = map.get("ts2");

        System.out.println("teachers = " + teachers);*/


    }
}
